/* SPDX-License-Identifier: GPL-2.0+
 *
 * (C) Copyright 2020
 * Anton Puiu, anton.puiu@email.com
 */

#include "mode.h"

MODE mode_get(const char *mode)
{
	if (mode == NULL) {
		return UNKNOWN_MODE;
	} else if (mode[0] == READ_MODE) {
		if (mode[1] == STR_TERMINATOR)
			return READ;
		else if (mode[1] == UPDATE_CHAR && mode[2] == STR_TERMINATOR)
			return READ_UPDATE;
	} else if (mode[0] == WRITE_MODE) {
		if (mode[1] == STR_TERMINATOR)
			return WRITE;
		else if (mode[1] == UPDATE_CHAR && mode[2] == STR_TERMINATOR)
			return WRITE_UPDATE;
	} else if (mode[0] == APPEND_MODE) {
		if (mode[1] == STR_TERMINATOR)
			return APPEND;
		else if (mode[1] == UPDATE_CHAR && mode[2] == STR_TERMINATOR)
			return APPEND_UPDATE;
	}

	return UNKNOWN_MODE;
}
